package org.example;

import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.Frame;

/**
 * @author zoush
 * @createTime 2024/11/28  14:55
 */
public class ConvertToMp4 {
    public static void main(String[] args) {
        String homePath = "E:\\FFOutput\\7fb3dd101c6efe7973be02ce85bcf09a.avi";
        String outputPath = "E:\\FFOutput\\7fb3dd101c6efe7973be02ce85bcf09a_1.mp4";


        try {
            FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(homePath);
            frameGrabber.start();

            FFmpegFrameRecorder frameRecorder = new FFmpegFrameRecorder(outputPath, frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), frameGrabber.getAudioChannels());
            frameRecorder.setFormat("mp4");
            frameRecorder.setFrameRate(frameGrabber.getFrameRate());
            frameRecorder.setSampleRate(frameGrabber.getSampleRate());
            frameRecorder.start();
            Frame frame;
            while ((frame = frameGrabber.grabFrame()) != null) {
                frameRecorder.record(frame);
            }
            frameRecorder.stop();
            frameGrabber.stop();
        } catch (Exception e) {
            System.out.printf("ceuwu:"+e);
        }


    }
}
